<template>
<div style="padding-top:200px;">

<yd-cell-group class="mt30" :title="$route.query.name">
    <!-- <yd-cell-item>
        <span slot="left">票码：</span>
        <yd-input slot="right" required v-model="form.code" max="20" placeholder="请输入票码"></yd-input>
    </yd-cell-item> -->

    <yd-cell-item>
        <span slot="left">票码：</span>
        <input slot="right" type="number" v-model="form.code" max="20" placeholder="请输入票码">

        <span slot="right" @click="openQRCode">扫码</span>
    </yd-cell-item>
</yd-cell-group>


<yd-button-group>
<!-- <yd-button size="small" @click.native="openQRCode">扫码</yd-button> -->
<yd-button size="large" type="primary" @click.native="gogo(0)">核销</yd-button>
<yd-button size="large" type="danger" @click.native="gogo(1)">强制核销(无视票种限制信息)</yd-button>
<yd-button size="large" type="hollow" @click.native="statistics(1)">核销统计(按型号)</yd-button>
<yd-button size="large" type="hollow" @click.native="statistics(0)">核销统计(按票种)</yd-button>
</yd-button-group>

</div>
</template>

<script>

import { mapGetters } from 'vuex'
import wx from '../../util/weixin'

export default {
	
	name : 'destroymain',
	
	data () {
		return {
		  	form : {
		  		code : '',
		  	}
		}
	},

	props : {

	},

	components : {
		
	},

	computed : {
		...mapGetters([
			'URL'
		]),
	},

	methods : {
		gogo (what) {

			console.log('gogog');
			let para = {
				fun : 'queryByCode',
				code : this.form.code,
				force : what,
				device : this.$route.query.devicecode,
				cb : res => {
					console.log('cb');
					console.log(res);

					this.$dialog.confirm({
	                    title: '确认核销',
	                    mes: '产品名：' + res.ticketInfo.product_name + '<br>' + 
	                         '型号名：' + res.ticketInfo.attr_name + '<br>' +
	                         '票种名：' + res.ticketInfo.type_name + '<br>',
	                    opts: () => {
	                        let para1 = {
								fun : 'destroyByCode',
								code : this.form.code,
								device : this.$route.query.devicecode,
								num : 1,
								reqkey : res.reqkey,
								force : what,
								cb : res1 => {
									console.log(res1);

									this.$dialog.toast({
					                    mes: '核销成功',
					                    timeout: 1500,
					                    icon: 'success',
					                });
								},
								err : res1 => {
									this.$dialog.toast({
					                    mes: res1,
					                    timeout: 1500,
					                    icon: 'error',
					                });
								}
							};

							this.$store.dispatch('update', para1);
	                    }
	                });
				},
				err : res => {
					console.log('err');
					console.log(res);
					this.$dialog.toast({
	                    mes: res,
	                    timeout: 1500,
	                    icon: 'error',
	                });
					//this.$message.error(res);
				}
			};

			this.$store.dispatch('update', para);
			
		},


		async openQRCode () {
			// wx.wexinQRCode(res => {

			// 	this.form.code = res;
			// });



			const result = await wx.wexinQRCode1(this.URL.ios);
			this.form.code = result;
		},


		statistics (what) {
			console.log('statistics');
			this.$router.push({ 
				'name': 'destroystatistics', 
				'params' : {
	    			'devicecode' : this.$route.query.devicecode,
	    			
	    		},
	    		query : {
	    			'what' : what,
	    		},
			});
		},
	},

	watch : {
	    
	},

	mounted () {
		console.log('this.router');
		console.log(this.$route);
		console.log(this.URL.shop1 + this.$route.fullPath);
	},

}
</script>

<style>
body {
	/*background-color: #fff;*/
}
</style>
